package 泛型机制Generic.Test01;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class GenericTest01 {
    public static void main(String[] args) {
        /*
        List myList = new ArrayList();
        Cat c = new Cat();
        Bird b = new Bird();
        myList.add(c);
        myList.add(b);
        Iterator it = myList.iterator();
        while(it.hasNext()){
            Object obj = it.next();
            if(obj instanceof Cat){
                Cat cat = (Cat)obj;
                cat.catchMouse();
            }else if(obj instanceof Bird){
                Bird bird = (Bird)b;
                bird.fly();
            }
        }
        */
        List<Animal> myList = new ArrayList<Animal>();
        Cat c = new Cat();
        Bird b = new Bird();
        //myList.add(1);    Error:(30, 20) java: 不兼容的类型: int无法转换为泛型机制Generic.Test01.Animal
        myList.add(c);
        myList.add(b);
        Iterator<Animal> it = myList.iterator();
        while(it.hasNext()){
            Animal animal = it.next();
            animal.move();
        }
    }
}
